// import config from '../config';
import mathTool from '../../../common/mathTool';

import passwordDialog from '../passwordDialog.html';
import confirm from "../../confirm/confirm";
import './list.less';

class ListController {
    /**
     *
     * @param $scope
     */
    constructor($scope, settingsSvc, $uibModal, $location, $cookies) {
        "ngInject";

        this.$scope = $scope;
        this.service = settingsSvc;
        this.$uibModal = $uibModal;
        this.$location = $location;
        this.$cookies = $cookies;

        this.data = {
            status: [
                {value: 'INIT', label: '初始化'},
                {value: 'LISTED', label: '交易对开'},
                {value: 'DELISTED', label: '交易对关'}
            ],
            type: [
                {value: 'COIN', label: 'COIN'},
                {value: 'CASH', label: 'CASH'},
            ]
        };


        this.form = {
            assetCode: '',
            status: 'INIT',     // 币种默认状态
            name: '',

            // 选填
            currencyType: 'COIN',   // 币种类型，默认coin，暂时都是COIN类型
            supplyAmount: '33333333333',    // 官方流通量，暂时不用
            totalAmount: '55555555555555',
            minPrecision: 8,
            description: '',
            webUrl: ''
            // coinImg: ''
        }
    }

    submit() {
        let that = this;
        if ($.trim(this.form.assetCode) === '') {
            window.toast('请输入币种代码');
            return;
        }

        // if ($.trim(this.form.status) === '') {
        //     window.toast('请选择币种状态');
        //     return;
        // }

        if ($.trim(this.form.name) === '') {
            window.toast('请输入币种名称');
            return;
        }

        // if ($.trim(this.form.type) === '') {
        //     window.toast('请输入币种类型');
        //     return;
        // }

        // if ($.trim(this.form.supplyAmount) === '') {
        //     window.toast('请输入币种供应数量');
        //     return;
        // }
        //
        // if ($.trim(this.form.totalAmount) === '') {
        //     window.toast('请输入币种总数量');
        //     return;
        // }
        //
        // if ($.trim(this.form.minPrecision) === '') {
        //     window.toast('请输入币种最小精度');
        //     return;
        // }

        // if ($.trim(this.form.description) === '') {
        //     window.toast('请输入币种描述');
        //     return;
        // }

        // if ($.trim(this.form.webUrl) === '') {
        //     window.toast('请输入币种官网');
        //     return;
        // }

        // if ($.trim(this.form.coinImg) === '') {
        //     window.toast('请上传币种图片');
        //     return;
        // }

        let modalInstance = this.$uibModal.open({
            template: passwordDialog,
            scope: this.$scope,
            controller() {
            }
        });

        let param = {
            assetCode: this.form.assetCode.toUpperCase(),
            status: this.form.status,     // 币种默认状态
            name: this.form.name,

            // 选填
            currencyType: this.form.currencyType,   // 币种类型，默认coin，暂时都是COIN类型
            supplyAmount: this.form.supplyAmount,    // 官方流通量，暂时不用
            totalAmount: this.form.totalAmount,
            minPrecision: this.form.minPrecision
        };

        if ($.trim(this.form.description) === '') {
            param.description = '0';
        } else {
            param.description = this.form.description;
        }
        if ($.trim(this.form.webUrl) === '') {
            param.webUrl = '0';
        } else {
            param.webUrl = this.form.webUrl;
        }

        this.$scope.$$ok = function (password) {
            window.toast('请稍候...');
            that.service.coinAdd(param, {
                'login-password': password
            }).then(rep => {
                if (rep.code === '100200') {
                    window.toast('添加成功', {
                        callback() {
                            window.location.reload();
                        }
                    });
                } else {
                    window.toast(rep.msg);
                }
            });
            modalInstance.dismiss('ok');
        };

        this.$scope.$$cancel = function () {
            modalInstance.dismiss('cancel');
        };

    }

}


export default ListController;
